<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Registration extends MX_Controller {
	
	protected $id = 0;
	
	protected $record_per_page = 0;
	
	protected $validation;
	
	
	public function __construct()
    {
		$this->load->library('users/auth');
		
		$this->load->library('form_validation');
		
		$this->form_validation->CI =& $this;
		
		$this->lang->load('transaction/registration');
		
		$this->load->model('admin/setup_m', 'numbering');
		$this->load->model('transaction/transaction_m', 'transaction');
		
		$this->validation = array(
								array(
									'field'	=> 'number',
									'label'	=> 'lang:registration_label_reg_num',
									'rules' => 'trim|htmlspecialchars|max_length[20]'
								),
								array(
									'field'	=> 'customer_id',
									'label'	=> 'lang:registration_label_customer',
									'rules'	=> 'trim|htmlspecialchars|required|max_length[20]'
								),
								array(
									'field'	=> 'memo',
									'label'	=> 'lang:registration_label_memo',
									'rules'	=> 'trim|htmlspecialchars'
								)
							);
		
		$this->template
				->set_theme('default')
				->set_layout('default')
				->append_metadata($this->asset->css('reset.css'))
				->append_metadata($this->asset->css('admin/default.css'))
				->append_metadata($this->asset->css('token-input.css'))
				->append_metadata($this->asset->css('admin/app.css'))
				->append_metadata($this->asset->css('notifcation.slider.css'))
				->append_metadata($this->asset->css('admin/jquery.accordion.css'))	
				->append_metadata($this->asset->css('general.css'))
				->append_metadata($this->asset->js('jquery/jquery-1.6.2.min.js'))
				->append_metadata($this->asset->js('jquery_accordion_init.js'))
				->append_metadata($this->asset->js('jquery.freeow.js'))
				->append_metadata($this->asset->js('jquery.tokeninput.js'))
				->append_metadata($this->asset->js('notificationBox.jquery.js'))
				->set_partial('header', 'partials/header')
				->set_partial('breadcrumb','partials/breadcrumb')
                ->set_partial('footer', 'partials/footer')
				->set_partial('navigation', 'partials/admin/menu')
				->set_breadcrumb('Home', 'admin/dashboard');
	}
	
	public function register()
	{
		$this->form_validation->set_rules($this->validation);
		
		if ($this->form_validation->run())
		{		
			$this->transaction->create_invoice_transaction();
			
			$this->session->set_flashdata('msg_title',lang('student_success_title'));
			$this->session->set_flashdata('msg',lang('success_success_insert'));
			redirect('student/student/');
		}
		
		$data['page_label'] 		= 'INVOICE';
		
		$data['invoice_number']		= $this->numbering->generate_invoice();
		
		$this->template
					->append_metadata($this->asset->js('jquery.tab.init.js'))
					->append_metadata($this->asset->css('admin/jquery.tab.css'))
					->set_breadcrumb('Invoice','student/lists')
					->set_breadcrumb('New')
					->build('transaction/registration/create', $data);
	}
}